<template>
    <Card>
        <p slot="title" class="card-title">
            <Icon type="person-stalker"></Icon>
            <span>查询</span>
        </p>
        <template>
            <Row>
                <Col span="24">
                <Form ref="search_info" class="search-info" :label-width="100" :model="search_info"  style="flex: 0 0 100%" inline>
                    <Col span="8">
                    <Form-item label="商户名" prop="trueOrFalse">
                        <Input v-model="dataInfo.merName" placeholder="" style="width: 200px"/>
                    </Form-item>
                    </Col>

                    <!--<Col span="8">-->
                    <!--<Form-item label="姓名" prop="trueOrFalse">-->
                        <!--<Input v-model="dataInfo.name" placeholder="" style="width: 200px"/>-->
                    <!--</Form-item>-->
                    <!--</Col>-->

                    <Col span="8">
                    <Form-item label="商家状态" prop="state" style="width: 200px">
                        <Select v-model="dataInfo.signState"  style="width: 200px">
                            <Option value="1">拒绝</Option>
                            <Option value="2">通过</Option>
                            <Option value="3">未审核</Option>
                        </Select>
                    </Form-item>
                    </Col>

                    <!--<Col span="8">-->
                    <!--<Form-item label="添加时间" prop="请选择时间" style="width: 200px">-->
                        <!--<DatePicker type="daterange" :options="options2"  v-model="optionsData"confirm placement="bottom-end" @on-ok="handleOk(optionsData)" placeholder="请选择时间" style="width: 200px"></DatePicker>-->

                    <!--</Form-item>-->
                    <!--</Col>-->

                    <Col span="8">
                    <Form-item label="状态" prop="productCode" style="width: 200px">
                        <Select v-model="dataInfo.state"  style="width: 200px">
                            <Option value="1">禁用</Option>
                            <Option value="2">启用</Option>
                        </Select>
                    </Form-item>
                    </Col>
                </Form>
                </Col>
                <div style="margin-top: 2rem;text-align: center">
                    <Button type="primary" icon="ios-search" @click="doGetDetail" style="margin-right: 8px">搜索</Button>
                    <!--<Button type="primary"  @click="addWhite" style="margin-right: 8px">添加</Button>-->
                </div>
            </Row>

            <div style="margin-top: 2rem;text-align: center">
                <Table ref="table"  class="margin-bottom-10" :columns="columns"
                       :border="setting.showBorder" :data="data.content" style="margin-top: 1.5rem">
                </Table>
                <Page :total="data.totalElements" class="tr" @on-change="pageChange":current.sync="dataFilter.current" :page-size="data.size"
                      @on-page-size-change="pageSizeChange" show-elevator show-sizer>
                </Page>
            </div>

        </template>

    </Card>
</template>

<script>
    import {post,get} from '../../../libs/axios-cfg';
    import moment from 'moment'
    export default {
        name: "index",
        data () {
            return {
                addWhiteModel: false,
                updateWhiteModel: false,
                tOrF_list: [],
                optionsData: '',
                search_info: {
                    signState: '',
                    name: '',
                    status: '',
                    productCode: ''
                },
                dataFilter: {
                    page: 0,
                    size: 10
                },
                updataId: '',
                formInfoup: {
                    uname:"",
                    uid :"",
                    phone: '',
                    amount: '',
                    ucard:"",
                    bankName:"",
                    createTime:"",
                    // signTime:"",
                    // ustate: '',
                    property:'',
                    mid: "",
                    signState:'1'
                },
                formInfo: {
                    uname:"",
                    uid :"",
                    phone: '',
                    amount: '',
                    ucard:"",
                    bankName:"",
                    createTime: moment(new Date()).format('YYYY年MM月DD日 HH:mm:ss'),
                    // signTime:"",
                    // ustate: '',
                    property:'',
                    mid: "",
                    signState:'1'
                },
                setting: {
                    loading: true,
                    showBorder: true
                },
                dataInfo: {
                    state: '',
                    endTime: '',
                    startTime: '',
                    signState: '',
                    merName: ''
                },
                options2: {
                    shortcuts: [
                        {
                            text: '本周',
                            value () {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                                return [start, end];
                            },
                            onClick: (picker) => {
                                console.log("picker"+picker)
                                debugger
                            }
                        },
                        {
                            text: '本月',
                            value () {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                                return [start, end];
                            },
                            onClick: (picker) => {
                                console.log("picker"+picker)
                                debugger
                            }
                        },
                        {
                            text: '最近3月',
                            value () {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                                return [start, end];
                            },
                            onClick: (picker) => {
                                console.log("picker"+picker)
                                debugger
                            }
                        }
                    ]
                },
                columns: [
                    {
                        type: 'selection',
                        width: 60,
                        align: 'center'
                    },
                    {
                        title: '商户名',
                        key: 'mname'
                    },
                    {
                        title: '姓名',
                        key: 'contactName'
                    },
                    {
                        title: '联系号码',
                        key: 'contactMobile'
                    },
                    {
                        title: '联系地址',
                        key: 'corpBusinessAddress'
                    },
                    {
                        title: '创建日期',
                        width: 200,
                        key: 'signState',
                        render:(h,params)=>{
                            return h('span',moment(params.row.signState).format('YYYY年MM月DD日 HH:mm:ss'))
                        },

                    },
                    {
                        title: '审核状态',
                        key: 'signState'
                    },
                    {
                        title: '状态',
                        key: 'status',
                        render:(h,params)=>{
                            return h('span',
                                {
                                    style: {color: params.row.userStatus == 1 ? 'green' : 'red'
                                    }
                                }, params.row.mstate == 1 ? '禁用' : '启用')
                        },

                    },

                    {
                        title: '操作',
                        align: 'center',
                        key: 'enable',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px',
                                        color: '#ffffff',
                                        backgroundColor: '#87b87f'
                                    },
                                    on: {
                                        click: () => {
                                            this.approve(params.row);
                                        }
                                    }

                                }, '同意'),
                                h('Button', {
                                    props: {
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px',
                                        color: '#ffffff',
                                        backgroundColor: '#87b87f'
                                    },
                                    on: {
                                        click: () => {
                                            this.reject(params.row)
                                        }
                                    }

                                }, '拒绝'),
                            ]);
                        }
                    },
                ],
                data: []
            }
        },
        mounted () {
            this.getWriteDataList()
        },
        methods : {
            async reject (obj) {

                // signState  1 拒绝 2 同意
                try{
                    let res = await post('/approval/merchant',{
                        id: obj.mid,
                        signTime: obj.signTime,
                        signState:1
                    })
                    this.$Message.success(res.data)
                }catch (e){
                    this.$throw(e)
                }
            },
            async approve(obj) {
                // signState  1 拒绝 2 同意
                try{
                    let res = await post('/approval/merchant',{
                        id: obj.mid,
                        signTime: obj.signTime,
                        signState:2
                    })
                    this.$Message.success(res.data)
                }catch (e){
                    this.$throw(e)
                }
            },
            update (obj) {
                this.formInfoup =  obj
                this.updataId = obj.id
                this.updateWhiteModel = true
            },
            async ok(tyep){
                let type = type
                if(type == 'add') {
                    try {
                        let res = await post ('/white/save',this.formInfo)
                        this.$Message.success(res.msg)
                        this.addWhiteModel = false
                        this.getWriteDataList()

                    }catch (e){
                        this.$throw(e)
                    }
                }else {
                    try {
                        let res = await post ('/white/save',this.formInfoup)
                        this.$Message.success(res.msg)
                        this.addWhiteModel = false
                        this.getWriteDataList()

                    }catch (e){
                        this.$throw(e)
                    }
                }

            },
            async getWriteDataList () {
                try {
                    let res = await post ('/merchant/query/list',{
                        endTime: this.dataInfo.endTime,
                        page: this.dataFilter.page,
                        size: this.dataFilter.size,
                        merName: this.dataInfo.merName,
                        merState: this.dataInfo.merState,
                        startTime: this.dataInfo.startTime
                    })
                    this.data = res.data
                }catch (e){
                    this.$throw(e)
                }
            },
            async delete(obj) {
                try{
                    let res = await get ('/white/delete/'+obj.id)
                    this.$Message.success(res.msg)
                    this.getWriteDataList()
                } catch (e){
                    this.$throw(e)
                }
            },
            doGetDetail () {
                this.getWriteDataList()
            },
            onOk () {
                console.log('asdads')
            },
            addWhite () {
                this.addWhiteModel = true
            },
            async payMountFasle (obj) {
                try {
                    let res = await post('/withhold/payment',{
                        uname: obj.uname,
                        uid: obj.uid,
                        ucard: obj.ucard,
                        wtype:1,
                        amount: obj.amount,
                        uphone: obj.uphone,
                        // underAmountId:1
                    })
                    this.$Message.success(res.data)
                }catch (e){
                    this.$throw(e)
                }
            },
            async payMountSave(obj) {
                try {
                    let res = await post('/withhold/payment',{
                        uname: obj.uname,
                        uid: obj.uid,
                        ucard: obj.ucard,
                        wtype:1,
                        amount: obj.amount,
                        uphone: obj.uphone,
                        underAmountId:1
                    })
                    this.$Message.success(res.data)
                }catch (e){
                    this.$throw(e)
                }

            },
            handleOk (picker) {
                this.dataInfo.startTime = moment(picker[0]).format('YYYY-MM-DD')
                this.dataInfo.endTime = moment(picker[1]).format('YYYY-MM-DD')
            },
            handleSelectAll (status) {
                this.$refs.selection.selectAll(status);
            },
            pageChange(p) {
                this.dataFilter.page = p;
                this.getWriteDataList();
            },
            pageSizeChange(p) {
                this.dataFilter.pageSize = p;
                this.getWriteDataList();
            },
        }
    }
</script>

<style scoped>

</style>
